<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<html>
   <head>
	   <script>
		  function processURL() {
		    document.getElementById("answercheckblock").innerHTML = '';
			var filltype = getCheckedRadio("filltype");
			if(filltype.length == '') {
			   alert('Please select a question type');
			   return;
			}
			url = '/lwf/fillblanks.do?action=selectoperation&filltype='+filltype;
		    retrieveURL(url, 'questionblock');
		    
		  }
		  
		  function checkAnswer() {
		  	var userans = readAnswers();
		  	//alert(userans);
			url = '/lwf/fillblanks.do?action=checkanswer&useranswer=' + userans;
		    retrieveURL(url, 'answercheckblock');
		  } 
		  
		  function processEnterKey() {
		     if(window.event.keyCode == 13) {
		        alert('Enter Key Pressed');
		        checkAnswer();
		     }
		  }
		  
		   function readAnswers(){
		      var answers = '';
		      var elementz = eval('document.' + getFormName() + '.elements.length');
		      var i;var el;
		      for (i=0;i<elementz;i++) {
		         el = eval('document.' + getFormName() + '.elements[i]');
		         //alert(el.type);
			      if(el.type == 'text') {
			         //alert('Element Name: ' + el.name + ' & Value: ' + el.value);
			         answers += el.value + ",";
			      }
		      }
		      return answers.substring(0, answers.length-1);
		   }
	   </script>
   </head>
   <html:form action="/fillblanks" >
   <table border="0" align="center" width="100%" bordercolor="red"> 
       <tr>
           <td>
               <table border="0" width="100%">
                  <tr>
                      <td width="28%" class="heading1" nowrap><b>Select fill type:</b></td>
	                  <td width="3%"><input type="radio" value="alphabet" name="filltype" onclick="processURL()"/></td>
	                  <td width="15%" class="leftlabel">Missing Alphabet</td>
	                  <td width="3%"><input type="radio" value="number" name="filltype" onclick="processURL()"/></td>
	                  <td width="15%" class="leftlabel">Missing Number</td>
	                  <td width="36%" nowrap>&nbsp;</td>
	               </tr>
                   <tr>
                      <td colspan="6">&nbsp;</td>
                   </tr>
               </table>
           </td>
       </tr>
       <tr>
           <td>
               <table border="0" width="100%">
                  <tr>
                      <td align="center">
                         <span id="answercheckblock"></span>
                      </td>
                  </tr>
                  <tr>
                      <td>
                         <span id="questionblock"></span>
                      </td>
                  </tr>                  
               </table>
           </td>
       </tr> 
   </table>  
   </html:form>
</html>